/**
 * Created by admin on 2017/9/25.
 */
/**
 * Created by admin on 2017/9/22.
 */
define([
        "helpers/network"
    ], function (Network) {

        function setPageCount(pageCount) {
            this.pageCount = pageCount
        }

        function setPageIndex(pageIndex) {
            this.pageIndex = pageIndex
        }

        function refreshPager(curPage, pageCount) {
            if (!curPage) {
                $$(this.pagerViewId).config.page = 0;
            }
            $$(this.pagerViewId).define("count", pageCount || 1);
            this.pageCount = pageCount || 1;
            this.pageIndex = curPage || 1;
            $$(this.pagerViewId).refresh();
        }

        function genPagerUI(viewId, onClick) {
            this.pagerViewId = viewId;
            this.pageCount = 1;
            this.pageIndex = 1;
            var that = this;
            return {
                id: viewId, view: 'pager', master: false, size: 1, group: 5, count: 1, minWidth: 420,height:38,
                template: '{common.first()} {common.prev()} {common.pages()} {common.next()} {common.last()}',
                on: {
                    onItemClick: function (id, e, node) {
                        if (id == "prev") {
                            that.pageIndex = that.pageIndex - 1
                            if (that.pageIndex < 1) {
                                that.pageIndex = 1
                            }
                        } else if (id == "next") {
                            that.pageIndex += 1;
                        } else if (id == "first") {
                            that.pageIndex = 1
                        } else if (id == "last") {
                            that.pageIndex = that.pageCount
                        } else {
                            that.pageIndex = Number(id) + 1
                        }
                        if (that.pageIndex > that.pageCount) {
                            that.pageIndex = that.pageCount;
                            return
                        }
                        if (onClick) {
                            onClick(that.pageIndex)
                        }
                    }
                }
            }
        }

        function genTotalCountsUI(viewId) {
            return {view: 'label', id: viewId, label: "0条记录, 共0页"}
        }

        function genSubtotalSummaryUI(viewId, data) {
            return {
                view: "template", id: viewId, autoheight: true, borderless: true, value: data || {},
                template: function (obj) {
                    return "<div style='display: flex'>" +
                        "<div class='summary-text'>小计(当页)</div>" +
                        "<div class='summary-title'>订单金额</div>" +
                        "<div class='summary-value'>" + (obj.betTotalAmount ? Number(obj.betTotalAmount).toCurrency() : "0".toCurrency()) + "</div>" +
                        "<div class='summary-title'>彩民承担</div>" +
                        "<div class='summary-value'>" + (obj.userFloatingProfitAndLoss ? Number(obj.userFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
                        "<div class='summary-title'>彩店承担</div>" +
                        "<div class='summary-value'>" + (obj.conductorFloatingProfitAndLoss ? Number(obj.conductorFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div></div>"
                }
            }
        }

        function genTotalSummaryUI(viewId, data) {
            return {
                view: "template", id: viewId, autoheight: true, borderless: true, value: data || {},
                template: function (obj) {
                    return "<div style='display: flex'>" +
                        "<div class='summary-text'>合计(当前条件)</div>" +
                        "<div class='summary-title'>订单金额</div>" +
                        "<div class='summary-value'>" + (obj.betTotalAmount ? Number(obj.betTotalAmount).toCurrency() : "0".toCurrency()) + "</div>" +
                        "<div class='summary-title'>彩民承担</div>" +
                        "<div class='summary-value'>" + (obj.userFloatingProfitAndLoss ? Number(obj.userFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
                        "<div class='summary-title'>彩店承担</div>" +
                        "<div class='summary-value'>" + (obj.conductorFloatingProfitAndLoss ? Number(obj.conductorFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div></div>"
                }
            }
        }

    //出票彩民
    function genUserSubtotalSummaryUI(viewId, data) {
        return {
            view: "template", id: viewId, autoheight: true, borderless: true, value: data || {},
            template: function (obj) {
                return "<div style='display: flex'>" +
                    "<div class='summary-text'>小计(当页)</div>" +
                    "<div class='summary-title'>出票金额</div>" +
                    "<div class='summary-value'>" + (obj.vTicketedAmount ? Number(obj.vTicketedAmount).toCurrency() : "0".toCurrency()) + "</div>" +
                    "<div class='summary-title'>彩民承担</div>" +
                    "<div class='summary-value'>" + (obj.userFloatingProfitAndLoss ? Number(obj.userFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
                    "<div class='summary-title'>彩店承担</div>" +
                    "<div class='summary-value'>" + (obj.conductorFloatingProfitAndLoss ? Number(obj.conductorFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div></div>"
            }
        }
    }

    //出票彩民
    function genUserTotalSummaryUI(viewId, data) {
        return {
            view: "template", id: viewId, autoheight: true, borderless: true, value: data || {},
            template: function (obj) {
                return "<div style='display: flex'>" +
                    "<div class='summary-text'>合计(当前条件)</div>" +
                    "<div class='summary-title'>出票金额</div>" +
                    "<div class='summary-value'>" + (obj.vTicketedAmount ? Number(obj.vTicketedAmount).toCurrency() : "0".toCurrency()) + "</div>" +
                    "<div class='summary-title'>彩民承担</div>" +
                    "<div class='summary-value'>" + (obj.userFloatingProfitAndLoss ? Number(obj.userFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
                    "<div class='summary-title'>彩店承担</div>" +
                    "<div class='summary-value'>" + (obj.conductorFloatingProfitAndLoss ? Number(obj.conductorFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div></div>"
            }
        }
    }

    // function genTradeSubtotalSummaryUI(viewId, data) {
    //     return {
    //         view: "template", id: viewId, autoheight: true, borderless: true, value: data || {},
    //         template: function (obj) {
    //             return "<div style='display: flex'>" +
    //                 "<div class='summary-text'>小计(当页)</div>" +
    //                 "<div class='summary-title'>购买金额</div>" +
    //                 "<div class='summary-value'>" + (obj.tradeTotalAmount ? Number(obj).toCurrency() : "0".toCurrency()) + "</div>" +
    //                 // "<div class='summary-title'>出售金额</div>" +
    //                 // "<div class='summary-value'>" + (obj.userFloatingProfitAndLoss ? Number(obj.userFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
    //                 // "<div class='summary-title'>彩店承担</div>" +
    //                 // "<div class='summary-value'>" + (obj.conductorFloatingProfitAndLoss ? Number(obj.conductorFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
    //                 "</div>"
    //         }
    //     }
    // }
    //
    // function genTradeTotalSummaryUI(viewId, data) {
    //     return {
    //         view: "template", id: viewId, autoheight: true, borderless: true, value: data || {},
    //         template: function (obj) {
    //             return "<div style='display: flex'>" +
    //                 "<div class='summary-text'>合计(当前条件)</div>" +
    //                 "<div class='summary-title'>购买金额</div>" +
    //                 "<div class='summary-value'>" + (obj.tradeTotalAmount ? Number(obj.tradeTotalAmount).toCurrency() : "0".toCurrency()) + "</div>" +
    //                 // "<div class='summary-title'>出售金额</div>" +
    //                 // "<div class='summary-value'>" + (obj.userFloatingProfitAndLoss ? Number(obj.userFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
    //                 // "<div class='summary-title'>彩店承担</div>" +
    //                 // "<div class='summary-value'>" + (obj.conductorFloatingProfitAndLoss ? Number(obj.conductorFloatingProfitAndLoss).toCurrency() : "0".toCurrency()) + "</div>" +
    //                 "</div>"
    //         }
    //     }
    // }


        return {
            setPageCount: setPageCount,
            setPageIndex: setPageIndex,
            genPagerUI: genPagerUI,
            genTotalCountsUI: genTotalCountsUI,
            refreshPager: refreshPager,
            genSubtotalSummaryUI: genSubtotalSummaryUI,
            genTotalSummaryUI: genTotalSummaryUI,
            genUserSubtotalSummaryUI:genUserSubtotalSummaryUI,
            genUserTotalSummaryUI:genUserTotalSummaryUI,
            // genTradeSubtotalSummaryUI:genTradeSubtotalSummaryUI,
            // genTradeTotalSummaryUI:genTradeTotalSummaryUI,
        }
    }
)
;